import java.util.HashMap;
import controlGraph.*;

public class StatementFactory {
	public static void main(String [] args) {
		// This hash records each label on the first pass.
		HashMap<String, Integer> labels = new HashMap<String, Integer>();
		Statement first = new DeclarationStatement("int", "a", 4, new ArrayLitExpression(new Expression[] {new LValueInt(1), new LValueInt(43), new LValueInt(51), new LValueInt(2)}));
		Statement decl14 = new DeclarationStatement("int", "y", 0, UndefinedExpression.getInstance());
		Statement decl15 = new DeclarationStatement("int", "x", 0, new LValueInt(0));
		labels.put("loop", Statement.getLastNum());
		Statement assign16 = new AssignmentStatement(new Variable("y"), new ArrayRef(new Expression[] {new Variable("a"), new Variable("x")}));
		Statement assign17 = new AssignmentStatement(new Variable("x"), new ArithExpr("+", new Variable("x"), new LValueInt(1)));
		Statement cond18 = new ConditionalGoto("loop", new ArithExpr("<", new Variable("x"), new LValueInt(4)));
		Statement goto19 = new Goto("end");
		Statement assign20 = new AssignmentStatement(new Variable("y"), new LValueInt(6));
		labels.put("end", Statement.getLastNum());
		Statement cond21 = new ConditionalGoto("loop", new ArithExpr("<", new Variable("y"), new ArrayRef(new Expression[] {new Variable("a"), new LValueInt(2)})));

		// Make a fake successor statement
		Statement.doneWithStatements();
		try {
			// Make a second pass, this time through the AST.
			// This gets line numbers from label names.
			Statement.processLabels(labels);

			// Begin the graph search
			first.visitSuccessors(new store(), new ArrayArith());
		} catch(InstantiationException ie) {

			// If a label is referenced, but never defined, we have
			// an invalid program. Print an error and exit.
			System.err.println("Bad label: " + ie.getMessage());
		}
	}
}
